﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Testcraft
{
    class OcclusionBlock
    {
        private GraphicsDevice device;
        private VertexPositionColor[] vertices = new VertexPositionColor[] 
        {
            new VertexPositionColor(new Vector3(-0.5f, 0.5f, 0.5f), Color.Red),
            new VertexPositionColor(new Vector3(0.5f, 0.5f, 0.5f), Color.Red),
            new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0.5f), Color.Red),
            new VertexPositionColor(new Vector3(0.5f, -0.5f, 0.5f), Color.Red),
            new VertexPositionColor(new Vector3(0.5f, 0.5f, -0.5f), Color.Red),
            new VertexPositionColor(new Vector3(-0.5f, 0.5f, -0.5f), Color.Red),
            new VertexPositionColor(new Vector3(0.5f, -0.5f, -0.5f), Color.Red),
            new VertexPositionColor(new Vector3(-0.5f, -0.5f, -0.5f), Color.Red),
        };

        private short[] indices = new short[] {
            0, 1, 2,
            1, 3, 2,
            1, 4, 3,
            4, 6, 3,
            4, 5, 6,
            5, 7 ,6,
            5, 0, 7,
            0, 2, 7,
            5, 4, 0,
            4, 1, 0,
            2, 3, 7,
            3, 6, 7,
        };

        public OcclusionBlock(GraphicsDevice device, Vector3 position, Vector3 size)
        {
            this.device = device;
            Matrix transformation = Matrix.CreateScale(size) * Matrix.CreateTranslation(position);
            for (int i = 0; i < this.vertices.Length; i++)
            {
                vertices[i].Position = Vector3.Transform(vertices[i].Position, transformation);
            }
        }

        public void Draw()
        {
            device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, this.vertices, 0, this.vertices.Length, this.indices, 0, this.indices.Length / 3);
        }
    }
}
